package ashok.corejava.threads;

import java.util.Scanner;

public class ThreadVolatile {

	public static void main(String args[]){
	
		Processor proc1= new Processor();
		
		proc1.start();
		System.out.println("Press Enter to stop");
		Scanner scanner = new Scanner(System.in);
		scanner.nextLine();
		proc1.shutdown();
	}
}

class Processor extends Thread{
	//Using volatile in thread programming to prevent caching the variables 
	//which are being used in threads.
	private volatile boolean running = true;
	public void run(){
		while(running){
			System.out.println("Hello");
			
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public void shutdown(){
		running = false;
	}
	
	
}
